package com.hxd.mall.module.product.home

import android.util.Log
import com.hxd.mall.network.base.BaseRequest
import com.hxd.mall.network.service.ManagerFunctionApi.mIConfigureFunctionApi
import com.hxd.mall.utils.open.ToastUtil
import javax.inject.Inject
import android.R.attr.data
import com.hxd.mall.constant.HxdConstants.product_channel
import com.hxd.mall.constant.HxdConstants.zoneID
import java.net.URLEncoder

/**
 * @author zhaoyong
 * @description:
 * @date :2019-07-19 18:43
 */
class HomePresenter @Inject constructor(var mView: IHomeView) : IHomePresenter {

    override fun getProductListData(productUrl: String, pageNumer: Int, pageSize: Int?) {
        // var path = "mall_commodity/app/v2/search/skus?keyword=沙琪玛&channel=tbk&hasCoupon=0"
        var url = productUrl+"&pageNum=${pageNumer}&pageSize=${pageSize}"
        BaseRequest.requestFinishRefresh(mIConfigureFunctionApi.getHomeProductData(url), mView, {
            //            BaseRequest.requestFinishRefresh(mIConfigureFunctionApi.searchProductData("哈哈哈", pageNumer, pageSize, "", "false", product_channel, zoneID), mView, {
            if (it.code == 0) {
                mView.getProductList(it)
                mView.finishRefresh()
            } else {
                mView.finishFailRefresh()
            }
        }, {
            ToastUtil.showToast(it.msg ?: "")
            mView.finishFailRefresh()
        })
    }

    //精选包邮  mall_content/app/v1/nine/layouts
    override fun jingXuanInfo(url: String) {
        BaseRequest.requestFinishRefresh(mIConfigureFunctionApi.getJinXuanData(url), mView, {
            mView.geJinXuanInfo(it)
            mView.finishRefresh()
        }, {
            ToastUtil.showToast(it.msg ?: "")
            mView.finishRefresh()
        })
    }

    //精选包邮列表
    override fun jingXuanInfoList(url: String, pageNumer: Int, pageSize: Int?) {
        var mUrl = url+"&pageNum=${pageNumer}&pageSize=${pageSize}"
        BaseRequest.requestFinishRefresh(mIConfigureFunctionApi.getJinXuanListData(mUrl), mView, {
            mView.getProductList(it)
            mView.finishRefresh()
        }, {
            ToastUtil.showToast(it.msg ?: "")
            mView.finishFailRefresh()
        })
    }

    //首页导航栏数据
    override fun getData(isRefresh: Boolean) {
        BaseRequest.requestFinishRefresh(mIConfigureFunctionApi.homeData, mView, {
            mView.netHomeData(it)
            mView.finishRefresh()
        }, {
            ToastUtil.showToast(it.msg ?: "")
            mView.finishRefresh()
        })
    }

    /**
     * 获取首页活动区的信息
     */
    override fun getProductStateData(url: String) {
        BaseRequest.request(mIConfigureFunctionApi.getHomeProDuctData("""$url"""), {
            // mView.getTbAutehrUrl(it)
            Log.d("getProductStateData", it.toString())

            mView.netHomeData(it)

            mView.finishRefresh()
        }, {
            //  mView.getTbAutehrUrl(null)
            ToastUtil.showToast(it.msg ?: "")
            mView.finishRefresh()
        })
    }

    /**
     * 淘宝授权URL
     */
    override fun uploadTaoBaoInfo() {
        BaseRequest.request(mIConfigureFunctionApi.uploadTaoBaoInfo(), {
            mView.getTbAutehrUrl(it)
        }, {
            mView.getTbAutehrUrl(null)
            ToastUtil.showToast(it.msg ?: "")
        })
    }

}